package com.keyancompany.zhongbaopingtai.api;

import android.text.TextUtils;

import com.keyancompany.zhongbaopingtai.ConstansUrl;
import com.keyancompany.zhongbaopingtai.activity.CreateCircleActivity;
import com.keyancompany.zhongbaopingtai.listener.IAsyncHttpResponseHandler;
import com.keyancompany.zhongbaopingtai.listener.LoadingHanlder;
import com.loopj.android.http.RequestParams;

import org.w3c.dom.Text;

import static com.keyancompany.zhongbaopingtai.api.UserAPI.SEARCH_COMMENT;

/**
 * Created by Gia on 2016/10/10.
 */
public class CircleAPI extends BaseAPI {

    public static final int SEARCH_CIRCLE_CODE = 0X311;

    public static final int UPADMIN_CODE = 0X312;
    public static final int TOPIC_REQUEST_CODE = 0X313;
    public static final int COMMENT_REQUEST_CODE = 0X314;
    public static final int SEARCH_ALL_CIRCLE_CODE = 0X315;
    public static final int ADD_TO_CIRCLE_BTME_CODE = 0X316;
//    public static final int SEARCH_CIRCLE_CODE = 0X317;

    public static final int EXIT_CIECLE_CODE = 0X318;
    public static final int GET_CIRCLE_ALLINFO_CODE = 0X319;
    public static final int SEARCH_FRIENG_CODE = 0X320;
    public static final int SEARCH_CODE = 0X321;
    public static final int ADD_FRIEND_CODE = 0X322;
    public static final int ADD_FRIEND_REQUEST_CODE = 0X323;
    public static final int GET_FRIEND_CLASS_CODE = 0X324;
    public static final int ADD_CIRLCE_REQUEST = 0x325;
    public static int ADD_TO_CIRLCE_REQUEST = 0x326;
    public static int SEARCH_REMEMBER = 0x327;
    public static int WRITE_RECORD = 0x328;
    public static int SEARCH_RECORD = 0x329;
    public static int SEARCH_COMMENT = 0x330;
    private static int GET_ALL_TOPIC = 0x331;
    private static int FSC_REQUEST = 0x332;
    private static int PL_SEARCH_RECORD = 0x333;
//    public static final int SEARCH_CODE = 0X325;

    /**
     * 我的圈子
     *
     * @param current
     * @param handler
     * @param loading
     */

    public static final void searchCircle(int current, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", current + "");
        params.put("pageSize", DETAULT_COUNT + "");
        post(ConstansUrl.SEARCH_CIRCLE, params, handler, SEARCH_CIRCLE_CODE, loading);

    }

    /**
     * 指定管理员
     *
     * @param pid     圈子id
     * @param userid  被提升的用户id
     * @param loading
     */
    public static final void upAdmin(String pid, String userid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("pid", pid);
        params.put("userid", userid);
        post(ConstansUrl.UPADMIN, params, handler, UPADMIN_CODE, loading);

    }

    /**
     * 发布话题
     *
     * @param pid
     * @param title
     * @param msg
     * @param handler
     * @param loading
     */
    public static final void topicRequest(String pid, String title, String msg, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("pid", pid);
        params.put("title", title);
        params.put("msg", msg);
        post(ConstansUrl.TOPIC_REQUEST, params, handler, TOPIC_REQUEST_CODE, loading);

    }

    /**
     * 圈子查询
     *
     * @param current
     * @param search
     * @param handler
     * @param loading
     */

    public static final void searchAllCircle(int current, String search, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", current + "");
        params.put("pageSize", DETAULT_COUNT + "");
        params.put("search", search);
        post(ConstansUrl.SEARCH_ALL_CIRCLE, params, handler, SEARCH_ALL_CIRCLE_CODE, loading);

    }

    /**
     * 加入圈子
     *
     * @param pid
     * @param handler
     * @param loading
     */
    public static final void addToCircleByme(String pid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("pid", pid);
        post(ConstansUrl.ADD_TO_CIRCLE_BTME, params, handler, ADD_TO_CIRCLE_BTME_CODE, loading);

    }

    public static final void exitCircle(String pid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("pid", pid);
        post(ConstansUrl.EXIT_CIECLE, params, handler, EXIT_CIECLE_CODE, loading);

    }

    /**
     * 获取圈子信息
     *
     * @param pid
     * @param handler
     * @param loading
     */
    public static final void getCircleAllInfo(String pid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("pid", pid);
        post(ConstansUrl.GET_CIRCLE_ALLINFO, params, handler, GET_CIRCLE_ALLINFO_CODE, loading);

    }


    /**
     * 获取圈子信息
     *
     * @param msgpid
     * @param state
     * @param handler
     * @param loading
     */
    public static final void getFriendClass(String msgpid, int state, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("msgpid", msgpid);
        params.put("state", state + "");

        post(ConstansUrl.GET_FRIEND_CLASS, params, handler, GET_FRIEND_CLASS_CODE, loading);

    }


    public static void addCircleRequest(String circleid, String circlename, String circleinfo, String kouHao,
                                        int autoenter, int autopass,
                                        IAsyncHttpResponseHandler handler, LoadingHanlder loading) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        if (!TextUtils.isEmpty(circleid)) {
            params.put("circleid", circleid);
        }
        params.put("circlename", circlename);
        if (!TextUtils.isEmpty(circleinfo)) {
            params.put("circleinfo", circleinfo);
        }
        if (!TextUtils.isEmpty(kouHao)) {
            params.put("kouHao", kouHao);
        }
        params.put("autoenter", autoenter + "");
        params.put("autopass", autopass + "");
        post(ConstansUrl.ADD_CIRLCE_REQUEST, params, handler, ADD_CIRLCE_REQUEST, loading);
    }

    public static void addToCircleRequest(String msgpid, String state,
                                          IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("msgpid", msgpid);
        params.put("state", state);

        post(ConstansUrl.ADD_TO_CIRLCE_REQUEST, params, handler, ADD_TO_CIRLCE_REQUEST, loading);
    }

    public static void searchMember(String pid, String currentPage, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("pid", pid);
        params.put("userId", UserAPI.getUserId());
        params.put("current", currentPage);
        params.put("pageSize", DETAULT_COUNT + "");

        post(ConstansUrl.SEARCH_REMEMBER, params, handler, SEARCH_REMEMBER, loading);
    }

    /**
     * 朋友圈列表
     *
     * @param currentPage
     * @param handler
     * @param loading
     */
    public static void searchRecord(String currentPage, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", currentPage);
        params.put("pageSize", DETAULT_COUNT + "");

        post(ConstansUrl.SEARCH_RECORD, params, handler, SEARCH_RECORD, loading);
    }

    /**
     * 圈子状态列表
     *
     * @param circlepid
     * @param current
     * @param handler
     * @param loading
     */
    public static void getAllTopic(String circlepid, String current, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("circlepid", circlepid);
        params.put("current", current);
        params.put("pageSize", DETAULT_COUNT + "");

        post(ConstansUrl.GET_ALL_TOPIC, params, handler, GET_ALL_TOPIC, loading);
    }

    /**
     * 发布朋友圈
     *
     * @param msg
     * @param handler
     * @param loading
     */
    public static void writeRecord(String msg, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("msg", msg);

        post(ConstansUrl.WRITE_RECORD, params, handler, WRITE_RECORD, loading);
    }

    /**
     * 圈子评论列表
     *
     * @param pid
     * @param current
     * @param handler
     * @param loading
     */
    public static void searchComment(String pid, String current, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("topicid", pid);
        params.put("current", current);
        params.put("pageSize", DETAULT_COUNT + "");

        post(ConstansUrl.SEARCH_COMMENTSNS, params, handler, SEARCH_COMMENT, loading);
    }

    /**
     * 圈子回复评论
     *
     * @param pid
     * @param commentmsg
     * @param answerid
     * @param handler
     * @param loading
     */
    public static void commentRequest(String pid, String commentmsg, String answerid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("topicid", pid);
        params.put("commentmsg", commentmsg);
        if (!TextUtils.isEmpty(answerid))
            params.put("answerid", answerid);

        post(ConstansUrl.COMMENT_REQUEST, params, handler, COMMENT_REQUEST_CODE, loading);
    }

    /**
     * 朋友圈话题评论列表
     *
     * @param fcpid
     * @param current
     * @param handler
     * @param loading
     */
    public static void plsearchRecord(String fcpid, String current, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("fcpid", fcpid);
        params.put("current", current);
        params.put("pageSize", DETAULT_COUNT + "");

        post(ConstansUrl.PL_SEARCH_RECORD, params, handler, PL_SEARCH_RECORD, loading);
    }

    /**
     * 朋友圈回复评论
     *
     * @param pid
     * @param commentmsg
     * @param answerid
     * @param handler
     * @param loading
     */
    public static void fscRequest(String pid, String commentmsg, String answerid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("fcpid", pid);
        params.put("msg", commentmsg);
        if (!TextUtils.isEmpty(answerid))
            params.put("answerid", answerid);

        post(ConstansUrl.FSC_REQUEST, params, handler, FSC_REQUEST, loading);
    }

}
